"""example of how to cluster a graph based on edges curvatures"""
import numpy as np
import pickle

import networkx as nx

from pygenstability import pygenstability as pgs

from geometric_clustering import cluster_signed_modularity
from geometric_clustering import compute_curvatures

if __name__ == "__main__":
    graph = nx.read_gpickle("hox_gene_expression.gpickle")
    graph = nx.convert_node_labels_to_integers(graph)

    t_min = -4
    t_max = -0.5
    n_t = 200
    times = np.logspace(t_min, t_max, n_t)
    kappas = compute_curvatures(
        graph, times, n_workers=5, measure_cutoff=0, weighted_curvature=True
    )

    markovstab_results = pgs.run(
        nx.adjacency_matrix(graph, weight="weight"),
        constructor="continuous_combinatorial",
        times=times,
        n_louvain=200,
        n_louvain_VI=50,
        n_workers=5,
    )
    pickle.dump(markovstab_results, open("markovstab_results.pkl", "wb"))

    geometric_modularity_results = cluster_signed_modularity(
        graph,
        times,
        kappas,
        kappa0=0,
        n_louvain=200,
        n_workers=5,
        n_louvain_VI=50,
        with_postprocessing=True,
    )
    pickle.dump(geometric_modularity_results, open("geometric_modularity_results.pkl", "wb"))
